import { useCallback } from "react";
import { useService } from "../../../../lib/Service";
import { message } from "antd";

export const useExport = (activiyName?: string) => {
    const serviceApi = useService();
    return useCallback((newName: string) => {
        return new Promise((resolve, reject) => {
            serviceApi.send({
                endPoint: "setting.studentDataExport",
                uri: {
                    name: newName ?? activiyName
                }
            }).then(({ data }: any) => {
                window.open(data, "_blank");
                resolve({});
            }).catch((err) => {
                message.error(err.message ?? "导出失败");
                reject({});
            });
        });
    }, [activiyName]);
};